import { ToolTipItem } from "../../../../../com/mui/manager/ToolTipItem";
import { PetMingJuLevelInfo } from "../info/PetMingJuLevelInfo";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { Cache } from "../../../cache/Cache";
import { PulseSharedObject } from "../../player/PulseSharedObject";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { CheckBoxWin } from "../../common/alertwins/CheckBoxWin";
import { Language } from "../../../../../extend/language/Language";
import { PetMingUtil } from "../info/PetMingUtil";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { ColorConfig } from "../../../resource/ColorConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { EffectManager } from "../../../manager/EffectManager";
import { GuidePetLifeStyleRule } from "../../../rules/GuidePetLifeStyleRule";
import { GuideArrowManager } from "../../../manager/GuideArrowManager";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { LineBox } from "../../guide/LineBox";
type int = number;
//class PetMingJuLevelItem
    
    export  class PetMingJuLevelItem extends ToolTipItem
    {
        constructor()
        {
            super();
            this._selectFilter = new Object /* flash.filters.GlowFilter */(16776960, 1, 2, 2, 2);
            this._overFilter = new Object /* flash.filters.GlowFilter */(16776960, 1, 10, 10, 2);
            this.init();
            this.useHandCursor = true;
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOutHandler);
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            return;
        }

        public updateByLevelInfo(arg1: PetMingJuLevelInfo): void
        {
            this._levelInfo = arg1;
            this.showMaxEffect(arg1.isMaxCanPropCall);
            if (arg1.isCanPropCall) 
            {
                if (this._isLoad) 
                {
                    this._bitmap.bitmapData = GlobalClass.getBitmapData("PetMingLevel" + this._levelInfo.level);
                }
                this.buttonMode = true;
                this.useHandCursor = true;
                if (arg1.level != 5) 
                {
                    this.showFilter(false);
                }
                else 
                {
                    this.showFilter(true);
                }
            }
            else 
            {
                if (this._isLoad) 
                {
                    this._bitmap.bitmapData = GlobalClass.getBitmapData("PetMingLevel" + this._levelInfo.level + "0");
                }
                this.buttonMode = false;
                this.useHandCursor = false;
                this.showFilter(false);
            }
            if (arg1.isShowCallButton) 
            {
                if (!this._callBtn) 
                {
                    this._callBtn = ObjCreate.createGLoadedButton(ResFileConst.PetMingCall, 0, 60, 89, 34, null);
                    this._callBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCallBtnClickHandler);
                }
                if (!this.contains(this._callBtn)) 
                {
                    this.addChild(this._callBtn);
                }
                this.buttonMode = true;
                this.useHandCursor = true;
            }
            else if (this._callBtn && this.contains(this._callBtn)) 
            {
                this.removeChild(this._callBtn);
            }
            this.toolTipData = this.getTip();
            return;
        }

        public get levelInfo(): PetMingJuLevelInfo
        {
            return this._levelInfo;
        }

        /* internal  */init(): void
        {
            this._bitmap = new Object /* flash.display.Bitmap */();
            this.addChild(this._bitmap);
            LoaderHelp.addResCallBack(ResFileConst.PetMing, this.onLoadedHandler);
            return;
        }

        /* internal  */onLoadedHandler(): void
        {
            this._isLoad = true;
            if (this._levelInfo) 
            {
                if (this.levelInfo.isCanPropCall) 
                {
                    this._bitmap.bitmapData = GlobalClass.getBitmapData("PetMingLevel" + this._levelInfo.level);
                }
                else 
                {
                    this._bitmap.bitmapData = GlobalClass.getBitmapData("PetMingLevel" + this._levelInfo.level + "0");
                }
            }
            return;
        }

        /* internal  */onCallBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var isNeedAlert: Boolean;
            var goldJuTime: int;
            var tipContent: string;
            var onBtnClickHandler: Function;

            var loc1;
            goldJuTime = 0;
            tipContent = null;
            e = arg1;
            if (Cache.instance.petMing.isDoReplay || this._levelInfo == null) 
            {
                return;
            }
            isNeedAlert = !PulseSharedObject.isTodayNotTips("PetMingCall");
            if (isNeedAlert) 
            {
                onBtnClickHandler = (arg1: int, arg2: Boolean): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.PetMingOneKeyJu, {"level": _levelInfo.level, "type": 1}));
                        Alert.resetToDefault();
                    }
                    if (arg2) 
                    {
                        PulseSharedObject.save("PetMingCall", true);
                    }
                    return;
                }
                Alert.alertWinRenderer = CheckBoxWin;
                goldJuTime = Cache.instance.petMing.goldJuTime;
                if (Cache.instance.petMing.discountActiveOpen) 
                {
                    tipContent = Language.getStringByParam(54785, PetMingUtil.discountActivePrice, ItemsUtil.getItemName(this._levelInfo.costItemData) + "*" + this._levelInfo.huntInfo.itemCost, this.getName());
                }
                else if (goldJuTime < 10) 
                {
                    tipContent = Language.getStringByParam(54914, this._levelInfo.huntInfo.gold * 0.5, ItemsUtil.getItemName(this._levelInfo.costItemData) + "*" + this._levelInfo.huntInfo.itemCost, this.getName());
                }
                else 
                {
                    tipContent = Language.getStringByParam(54785, this._levelInfo.huntInfo.gold, ItemsUtil.getItemName(this._levelInfo.costItemData) + "*" + this._levelInfo.huntInfo.itemCost, this.getName());
                }
                Alert.show(tipContent, null, Alert.OK | Alert.CANCEL, null, onBtnClickHandler);
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetMingOneKeyJu, {"level": this._levelInfo.level, "type": 1}));
            }
            this.cooldown();
            if (e) 
            {
                e.stopPropagation();
            }
            return;
        }

        /* internal  */onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (Cache.instance.petMing.isDoReplay) 
            {
                return;
            }
            if (this.levelInfo.isShowCallButton) 
            {
                this.onCallBtnClickHandler(null);
                return;
            }
            if (this._levelInfo && this._levelInfo.isCanPropCall) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetMingOneKeyJu, {"level": this._levelInfo.level, "type": 0}));
            }
            else if (this._guideLineBox && this._guideLineBox.parent == this) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetMingOneKeyJu, {"level": this._levelInfo.level, "type": 0}));
            }
            this.cooldown();
            arg1.stopPropagation();
            return;
        }

        /* internal  */cooldown(): void
        {
            this.mouseEnabled = false;
            this.mouseChildren = false;
            if (!this._timer) 
            {
                this._timer = new Object /* flash.utils.Timer */(this._delay);
                this._timer.repeatCount = 1;
                this._timer.addEventListener(flash.events.TimerEvent.TIMER_COMPLETE, this.onTimerCompleteHandler);
            }
            this._timer.reset();
            this._timer.start();
            return;
        }

        /* internal  */onTimerCompleteHandler(arg1: Object /* flash.events.TimerEvent */): void
        {
            this.mouseEnabled = true;
            this.useHandCursor = true;
            this.mouseChildren = true;
            return;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._levelInfo && this._levelInfo.isCanPropCall) 
            {
                if (this._bitmap) 
                {
                    this._bitmap.filters = [this._overFilter];
                }
            }
            return;
        }

        /* internal  */onMouseOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._levelInfo && this._levelInfo.isMaxCanPropCall) 
            {
                if (this._bitmap) 
                {
                    this._bitmap.filters = [this._selectFilter];
                }
            }
            else if (this._bitmap) 
            {
                this._bitmap.filters = [];
            }
            return;
        }

        /* internal  */getTip(): string
        {
            var loc1=null;
            if (this._levelInfo) 
            {
                if (this._levelInfo.isCanPropCall) 
                {
                    loc1 = this.getName() + "\n" + Language.getStringByParam(54768, ItemsUtil.getItemName(this._levelInfo.costItemData) + "*" + this._levelInfo.huntInfo.itemCost);
                }
                else if (this._levelInfo.level != 4) 
                {
                    return null;
                }
                else if (Cache.instance.petMing.discountActiveOpen) 
                {
                    loc1 = this.getName() + Language.getStringByParam(54939, this._levelInfo.huntInfo.gold, ItemsUtil.getItemName(this._levelInfo.costItemData), this._levelInfo.huntInfo.itemCost, PetMingUtil.discountActivePrice, ItemsUtil.getItemName(this._levelInfo.costItemData), this._levelInfo.huntInfo.itemCost);
                }
                else 
                {
                    loc1 = this.getName() + Language.getStringByParam(54769, this._levelInfo.huntInfo.gold, ItemsUtil.getItemName(this._levelInfo.costItemData), this._levelInfo.huntInfo.itemCost, int(this._levelInfo.huntInfo.gold / 2), ItemsUtil.getItemName(this._levelInfo.costItemData), this._levelInfo.huntInfo.itemCost);
                }
            }
            return "<textFormat leading=\'3\'><font color=\'#ffffff\'>" + loc1 + "</font></textFormat>";
        }

        /* internal  */showMaxEffect(arg1: Boolean): void
        {
            if (arg1) 
            {
                if (!this._effectPlayer) 
                {
                    this._effectPlayer = new SWFPlayer();
                }
                this._effectPlayer.move(60, -10);
                if (!this.contains(this._effectPlayer)) 
                {
                    this.addChild(this._effectPlayer);
                }
                this._effectPlayer.timeRate = 4;
                this._effectPlayer.load("PetMingLevelMax.swf", ModelType.NormalSwf, null);
                if (this._bitmap) 
                {
                    this._bitmap.filters = [this._selectFilter];
                }
            }
            else 
            {
                if (this._effectPlayer && this.contains(this._effectPlayer)) 
                {
                    this.removeChild(this._effectPlayer);
                }
                if (this._bitmap) 
                {
                    this._bitmap.filters = [];
                }
            }
            return;
        }

        /* internal  */getName(): string
        {
            var loc2=null;
            var loc1="";
            if (this._levelInfo) 
            {
                loc2 = ColorConfig.instance.getItemColorString(this._levelInfo.level);
                loc1 = HTMLUtil.addColor(this._levelInfo.huntInfo.hunterName, loc2);
            }
            return loc1;
        }

        public guideLifeStyleOpt(arg1: int): void
        {
            this._guideLineBox = EffectManager.getLineBox(60, 60, [16776960, 16711680], 0.5, 2);
            if (arg1 != GuidePetLifeStyleRule.StepLifeStyleOpt1) 
            {
                if (arg1 == GuidePetLifeStyleRule.StepLifeStyleOpt2) 
                {
                    this._guideLineBox.x = 20;
                    this._guideLineBox.y = 0;
                }
            }
            else 
            {
                this._guideLineBox.x = 22;
                this._guideLineBox.y = -5;
            }
            addChild(this._guideLineBox);
            var loc1=GuideArrowManager.getGuideArrow(GuideArrowManager.Dir_B);
            loc1.x = this._guideLineBox.x + 30;
            loc1.y = this._guideLineBox.y;
            addChild(loc1);
            return;
        }

        public guideHide(): void
        {
            this.onRemoveFromStageHandler(null);
            return;
        }

        /* internal  */onRemoveFromStageHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._guideLineBox && this._guideLineBox.parent == this) 
            {
                EffectManager.disposeLineBox(this._guideLineBox);
                this._guideLineBox = null;
            }
            return;
        }

        /* internal  */showFilter(arg1: Boolean): void
        {
            if (arg1) 
            {
                EffectManager.glowFilterReg(this, [FilterConst.uiBtnFilter]);
            }
            else 
            {
                EffectManager.glowFilterUnReg(this);
            }
            return;
        }

        /* internal */ /* var */_selectFilter: Object /* flash.filters.GlowFilter */;

        /* internal */ /* var */_overFilter: Object /* flash.filters.GlowFilter */;

        /* internal */ /* var */_bitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_maxIconBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_effectPlayer: SWFPlayer;

        /* internal */ /* var */_callBtn: GLoadedButton;

        /* internal */ /* var */_lineBox: LineBox;

        /* internal */ /* var */_timer: Object /* flash.utils.Timer */;

        /* internal */ /* var */_levelInfo: PetMingJuLevelInfo;

        /* internal */ /* var */_isLoad: Boolean;

        /* internal */ /* var */_delay: int=0;

        /* internal */ /* var */_guideLineBox: LineBox;
    }
